#ifndef NG_PACKAGE_H
#define NG_PACKAGE_H

#include <nctl/String.h>
#include <nctl/Array.h>
#include <nctl/UniquePtr.h>

namespace nt = nctl;

namespace ng {
  class Package {
    public:
      struct PackageData {
        char *buffer;
        unsigned size;
      };
      struct PackageFile {
        nt::String name;
        unsigned long offset;
        unsigned size;
      };
      struct PackageItem {
        nt::String name;
        nt::Array<PackageFile> files_;
      };
    public:
      Package(bool readFromDisk);
      virtual ~Package();
    public:
      bool load(const nt::String &pkg);
      void unload(const nt::String &pkg);
      void unloadAll();
      const PackageItem* getItem(const nt::String &pkg) const;
      nt::UniquePtr<PackageData> getData(const PackageItem *item, const nt::String &file) const;
      nt::UniquePtr<PackageData> getData(const nt::String &pkg, const nt::String &file) const;
      nt::UniquePtr<PackageData> getData(const nt::String &file) const;
    protected:
      bool loadItem(PackageItem &pi);
      void unloadItem(PackageItem &pi);
      nt::UniquePtr<PackageData> getFileData(const PackageFile *pf) const;
      nt::UniquePtr<PackageData> getFileData(const nt::String &file) const;
    protected:
      bool readFromDisk_;
      nt::Array<PackageItem> pkgs_;
  };
} // end namespace ng

#endif // NG_PACKAGE_H